<template>
  <div class="m-order">
    <ul v-if="auth">
      <li v-if="cur.length">
        <el-row
          v-for="(item,idx) in cur"
          :key="idx">
          <el-col :span="4">
            <img
              :src="item.img"
              alt="">
          </el-col>
          <el-col :span="10">
            <h4>{{ item.name }}</h4>
            <p>数量：{{ item.count }}</p>
          </el-col>
          <el-col :span="4">
            总价：￥{{ item.total }}
          </el-col>
          <el-col :span="6">
            {{ item.statusTxt }}
          </el-col>
        </el-row>
      </li>
      <li
        v-else
        class="empty">没有订单</li>
    </ul>
    <div
      v-else
      class="deal-need-login">
      <img
        src="//p0.meituan.net/codeman/56a7d5abcb5ce3d90fc91195e5b5856911194.png"
        alt="登录查看">
      <span>请登录后查看</span>
      <el-button
        type="primary"
        round>
        <a href="/login">立即登录</a>
      </el-button>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    cur: {
      type:Array,
      default:()=>{
        return []
      }
    },
  },
  data() {
    return {
      auth: true
    }
  },
  async mounted() {
    const {status, data:{username} } = await this.$axios.get('/users/getUser')
    this.auth = status === 200 && username
  }
}
</script>

<style lang="scss">
  .deal-need-login {
    padding: 30px 0;
    margin-bottom: 40px;
    text-align: center;
    background-color: #fff;
    >img{
      display: inline-block;
      width: 160px;
      height: 120px;
      border-radius: 4px;
    }
    >span{
      display: block;
      margin: 10px 0 14px;
      color: #666;
      font-size: 16px;
      line-height: 26px;
    }
    >button{
      background-color: #13D1BE;
      border-color: #13D1BE;
      a{
        color: #fff;
      }
    }
  }
</style>